<?php
    \defined( '_JEXEC' ) or die( 'Restricted access' );
    // todo: me to document.load() steile mono thn lista tou menu ws JSON kai me javascript ftia3e to menu
    // 
    
//    echo "<pre>";
//    print_r(juven\libs\juven::user()->menus);
//    echo "</pre>";
    function userMenu2Bootstrap_NavBar(array $arr, $level=0, $menuDisplayName="", $ln="\n", $id_char="i"){
        $return = $level<1 ? "<ul class=\"nav navbar-nav\">$ln" : "<li class=\"dropdown\">$ln<a href=\"#\" class=\"dropdown-toggle\" data-toggle=\"dropdown\">".$menuDisplayName." <b class=\"caret\"></b></a>$ln<ul class=\"dropdown-menu\">$ln";
        foreach ($arr as $item){
            if (\count($item["c"])>0){
                $return .= "$ln".userMenu2Bootstrap_NavBar($item["c"],++$level, $item["display_name"]); $level--;
            } else { 
                $return .= "<li id=\"$id_char".$item["id"]."\"><a href=\"".juven\libs\juven::config()->siteRootUrl.$item["url_link"]."\">".$item["display_name"]."</a></li>$ln";
            }
        }
        $return .= $level<1 ? "</ul>$ln" : "</ul>$ln</li>$ln";
        return $return;
    }
    
?>
<!doctype html>
<html>
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <meta name="description" content="">
        <meta name="author" content="">
        <meta http-equiv="Content-Type" content="text/html;">
        
        <meta http-equiv="cache-control" content="max-age=0" />
        <meta http-equiv="cache-control" content="no-cache" />
        <meta http-equiv="expires" content="Tue, 01 Jan 1980 1:00:00 GMT" />
        <meta http-equiv="pragma" content="no-cache" />
        
        <link href="<?php echo juven\libs\juven::config()->siteRootUrl; ?>public/bootstrap_v3/css/bootstrap.min.css" rel="stylesheet" media="screen">
        <link href="<?php echo juven\libs\juven::config()->siteRootUrl; ?>public/bootstrap_v3/css/bootstrap-theme.min.css" rel="stylesheet" media="screen">
        <?php
            $f = juven\libs\juven::config()->cssFolderPath.$this->controllerName.\DIRECTORY_SEPARATOR.$this->actionName.".css";
            if (\is_readable($f)){
                echo "<link href=\"".juven\libs\juven::config()->siteRootUrl."public/css/".$this->controllerName."/".$this->actionName.".css\" rel=\"stylesheet\" media=\"screen\">";
            }
        ?>
        <script src="<?php echo juven\libs\juven::config()->siteRootUrl; ?>public/js/jquery-1.10.2.min.js"></script>
        <script src="<?php echo juven\libs\juven::config()->siteRootUrl; ?>public/js/knockout-3.0.0rc.js"></script>
        <script src="<?php echo juven\libs\juven::config()->siteRootUrl; ?>public/js/core.js"></script>
        <?php
            $f = juven\libs\juven::config()->jsFolderPath.$this->controllerName.\DIRECTORY_SEPARATOR.$this->actionName.".js";
            if (\is_readable($f)){
                echo "<script src=\"".juven\libs\juven::config()->siteRootUrl."public/js/".$this->controllerName."/".$this->actionName.".js\"></script>";
            }
        ?>
        <title>juven - <?php echo $this->pageTitle ?></title>
    </head>
    <body>
        
        <div class="container">
            <nav class="navbar navbar-default navbar-fixed-top" role="navigation">
              <div class="navbar-header">
                <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-ex1-collapse">
                  <span class="sr-only">Toggle navigation</span>
                  <span class="icon-bar"></span>
                  <span class="icon-bar"></span>
                  <span class="icon-bar"></span>
                </button>
                  <a class="navbar-brand" href="<?php echo \juven\libs\juven::config()->siteRootUrl; ?>"><?php echo \juven\libs\juven::config()->siteTitle; ?></a>
              </div>

              <div class="collapse navbar-collapse navbar-ex1-collapse">
                <?php echo userMenu2Bootstrap_NavBar(juven\libs\juven::user()->menus); ?> 
              </div><!-- /.navbar-collapse -->
            </nav>

            
            <?php 
//               echo "<pre>";
//               print_r(juven\libs\juven::user()->menus);
//               echo "</pre>";
            ?>

            